package org.ayachinene.leetcode.problems;

import org.ayachinene.leetcode.structure.TreeNode;

public class P100 {

    static class Solution {

        /**
         * 若p和q是相等的二叉树，返回true，否则返回false
         */
        public boolean isSameTree(TreeNode p, TreeNode q) {
            if (p == null) {
                return q == null;
            }

            if (q == null) {
                return false;
            }

            if (p.val != q.val) {
                return false;
            }

            return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
        }
    }
}
